export default {
  addCart(context, payload) {
    //1.查找之前数组中是否有该商品
    return new Promise((resolve, reject) => {
      let oldProducts = context.state.cartList.find(
        item => item.iid === payload.iid
      );

      //2.判断oldProducts
      if (oldProducts) {
        context.commit("addCounter", oldProducts);
        resolve("当前的商品数量+1");
      } else {
        payload.count = 1;
        context.commit("addProduct", payload);
        resolve("添加了新的商品");
      }
    });
  }
};
